<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveRecord::ConnectionAdapters::QueryCache</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveRecord::ConnectionAdapters::QueryCache</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001449">cache</a>&nbsp;&nbsp;
      <a href="#M001451">clear_query_cache</a>&nbsp;&nbsp;
      <a href="#M001453">columns_with_query_cache</a>&nbsp;&nbsp;
      <a href="#M001448">dirties_query_cache</a>&nbsp;&nbsp;
      <a href="#M001447">included</a>&nbsp;&nbsp;
      <a href="#M001452">select_all_with_query_cache</a>&nbsp;&nbsp;
      <a href="#M001450">uncached</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">query_cache</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">query_cache_enabled</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M001448" class="method-detail">
        <a name="M001448"></a>

        <div class="method-heading">
          <a href="#M001448" class="method-signature">
          <span class="method-name">dirties_query_cache</span><span class="method-args">(base, *method_names)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001448-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001448-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb, line 14</span>
14:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dirties_query_cache</span>(<span class="ruby-identifier">base</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">method_names</span>)
15:           <span class="ruby-identifier">method_names</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">method_name</span><span class="ruby-operator">|</span>
16:             <span class="ruby-identifier">base</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-value str">&quot;def \#{method_name}_with_query_dirty(*args)\nclear_query_cache if @query_cache_enabled\n\#{method_name}_without_query_dirty(*args)\nend\n\nalias_method_chain :\#{method_name}, :query_dirty\n&quot;</span>, <span class="ruby-keyword kw">__FILE__</span>, <span class="ruby-keyword kw">__LINE__</span>
17:           <span class="ruby-keyword kw">end</span>
18:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001447" class="method-detail">
        <a name="M001447"></a>

        <div class="method-heading">
          <a href="#M001447" class="method-signature">
          <span class="method-name">included</span><span class="method-args">(base)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001447-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001447-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb, line 5</span>
 5:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">included</span>(<span class="ruby-identifier">base</span>)
 6:           <span class="ruby-identifier">base</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
 7:             <span class="ruby-identifier">alias_method_chain</span> <span class="ruby-identifier">:columns</span>, <span class="ruby-identifier">:query_cache</span>
 8:             <span class="ruby-identifier">alias_method_chain</span> <span class="ruby-identifier">:select_all</span>, <span class="ruby-identifier">:query_cache</span>
 9:           <span class="ruby-keyword kw">end</span>
10: 
11:           <span class="ruby-identifier">dirties_query_cache</span> <span class="ruby-identifier">base</span>, <span class="ruby-identifier">:insert</span>, <span class="ruby-identifier">:update</span>, <span class="ruby-identifier">:delete</span>
12:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001449" class="method-detail">
        <a name="M001449"></a>

        <div class="method-heading">
          <a href="#M001449" class="method-signature">
          <span class="method-name">cache</span><span class="method-args">() {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Enable the query <a href="QueryCache.html#M001449">cache</a> within the
block.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001449-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001449-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb, line 32</span>
32:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cache</span>
33:         <span class="ruby-identifier">old</span>, <span class="ruby-ivar">@query_cache_enabled</span> = <span class="ruby-ivar">@query_cache_enabled</span>, <span class="ruby-keyword kw">true</span>
34:         <span class="ruby-ivar">@query_cache</span> <span class="ruby-operator">||=</span> {}
35:         <span class="ruby-keyword kw">yield</span>
36:       <span class="ruby-keyword kw">ensure</span>
37:         <span class="ruby-identifier">clear_query_cache</span>
38:         <span class="ruby-ivar">@query_cache_enabled</span> = <span class="ruby-identifier">old</span>
39:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001451" class="method-detail">
        <a name="M001451"></a>

        <div class="method-heading">
          <a href="#M001451" class="method-signature">
          <span class="method-name">clear_query_cache</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Clears the query <a href="QueryCache.html#M001449">cache</a>.
</p>
<p>
One reason you may wish to call this method explicitly is between queries
that ask the database to randomize results. Otherwise the <a
href="QueryCache.html#M001449">cache</a> would see the same SQL query and
repeatedly return the same result each time, silently undermining the
randomness you were expecting.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001451-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001451-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb, line 55</span>
55:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_query_cache</span>
56:         <span class="ruby-ivar">@query_cache</span>.<span class="ruby-identifier">clear</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@query_cache</span>
57:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001453" class="method-detail">
        <a name="M001453"></a>

        <div class="method-heading">
          <a href="#M001453" class="method-signature">
          <span class="method-name">columns_with_query_cache</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001453-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001453-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb, line 67</span>
67:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">columns_with_query_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
68:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@query_cache_enabled</span>
69:           <span class="ruby-ivar">@query_cache</span>[<span class="ruby-node">&quot;SHOW FIELDS FROM #{args.first}&quot;</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">columns_without_query_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
70:         <span class="ruby-keyword kw">else</span>
71:           <span class="ruby-identifier">columns_without_query_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
72:         <span class="ruby-keyword kw">end</span>
73:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001452" class="method-detail">
        <a name="M001452"></a>

        <div class="method-heading">
          <a href="#M001452" class="method-signature">
          <span class="method-name">select_all_with_query_cache</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001452-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001452-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb, line 59</span>
59:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">select_all_with_query_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
60:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@query_cache_enabled</span>
61:           <span class="ruby-identifier">cache_sql</span>(<span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>) { <span class="ruby-identifier">select_all_without_query_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>) }
62:         <span class="ruby-keyword kw">else</span>
63:           <span class="ruby-identifier">select_all_without_query_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
64:         <span class="ruby-keyword kw">end</span>
65:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001450" class="method-detail">
        <a name="M001450"></a>

        <div class="method-heading">
          <a href="#M001450" class="method-signature">
          <span class="method-name">uncached</span><span class="method-args">() {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Disable the query <a href="QueryCache.html#M001449">cache</a> within the
block.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001450-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001450-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb, line 42</span>
42:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uncached</span>
43:         <span class="ruby-identifier">old</span>, <span class="ruby-ivar">@query_cache_enabled</span> = <span class="ruby-ivar">@query_cache_enabled</span>, <span class="ruby-keyword kw">false</span>
44:         <span class="ruby-keyword kw">yield</span>
45:       <span class="ruby-keyword kw">ensure</span>
46:         <span class="ruby-ivar">@query_cache_enabled</span> = <span class="ruby-identifier">old</span>
47:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>